package com.donnow.usermanager.service.impl;

import com.donnow.usermanager.mapper.UserMapper;
import com.donnow.usermanager.model.User;
import com.donnow.usermanager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public User findById(Long id) {
        return userMapper.findById(id);
    }

    @Override
    public User create(User user) {
        userMapper.insert(user);
        return user;
    }

    @Override
    public User update(Long id, User user) {
        user.setId(id);
        userMapper.update(user);
        return user;
    }

    @Override
    public void delete(Long id) {
        userMapper.delete(id);
    }

    @Override
    public User findByName(String username){
        userMapper.findByName(username);
        return new User();
    }

    @Override
    public User findByEmail(String email){
        User user  = userMapper.findByEmail(email);
        return user;
    }
}
